﻿using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace TuLing.Blazor.Migrations
{
    public partial class changeFields : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_BuyOrderReturnDetails_SaleOrderReturns_SaleOrderReturnId",
                table: "BuyOrderReturnDetails");

            migrationBuilder.DropForeignKey(
                name: "FK_SaleOrderDetails_BuyOrders_BuyOrderId",
                table: "SaleOrderDetails");

            migrationBuilder.DropForeignKey(
                name: "FK_SaleOrderDetails_SaleOrders_SaleOrderId",
                table: "SaleOrderDetails");

            migrationBuilder.DropIndex(
                name: "IX_SaleOrderDetails_BuyOrderId",
                table: "SaleOrderDetails");

            migrationBuilder.DropIndex(
                name: "IX_BuyOrderReturnDetails_SaleOrderReturnId",
                table: "BuyOrderReturnDetails");

            migrationBuilder.DropColumn(
                name: "BuyOrderId",
                table: "SaleOrderDetails");

            migrationBuilder.DropColumn(
                name: "SaleOrderReturnId",
                table: "BuyOrderReturnDetails");

            migrationBuilder.AlterColumn<long>(
                name: "SaleOrderId",
                table: "SaleOrderDetails",
                type: "INTEGER",
                nullable: false,
                defaultValue: 0L,
                oldClrType: typeof(long),
                oldType: "INTEGER",
                oldNullable: true);

            migrationBuilder.AddForeignKey(
                name: "FK_SaleOrderDetails_SaleOrders_SaleOrderId",
                table: "SaleOrderDetails",
                column: "SaleOrderId",
                principalTable: "SaleOrders",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_SaleOrderDetails_SaleOrders_SaleOrderId",
                table: "SaleOrderDetails");

            migrationBuilder.AlterColumn<long>(
                name: "SaleOrderId",
                table: "SaleOrderDetails",
                type: "INTEGER",
                nullable: true,
                oldClrType: typeof(long),
                oldType: "INTEGER");

            migrationBuilder.AddColumn<long>(
                name: "BuyOrderId",
                table: "SaleOrderDetails",
                type: "INTEGER",
                nullable: false,
                defaultValue: 0L);

            migrationBuilder.AddColumn<long>(
                name: "SaleOrderReturnId",
                table: "BuyOrderReturnDetails",
                type: "INTEGER",
                nullable: true);

            migrationBuilder.CreateIndex(
                name: "IX_SaleOrderDetails_BuyOrderId",
                table: "SaleOrderDetails",
                column: "BuyOrderId");

            migrationBuilder.CreateIndex(
                name: "IX_BuyOrderReturnDetails_SaleOrderReturnId",
                table: "BuyOrderReturnDetails",
                column: "SaleOrderReturnId");

            migrationBuilder.AddForeignKey(
                name: "FK_BuyOrderReturnDetails_SaleOrderReturns_SaleOrderReturnId",
                table: "BuyOrderReturnDetails",
                column: "SaleOrderReturnId",
                principalTable: "SaleOrderReturns",
                principalColumn: "Id");

            migrationBuilder.AddForeignKey(
                name: "FK_SaleOrderDetails_BuyOrders_BuyOrderId",
                table: "SaleOrderDetails",
                column: "BuyOrderId",
                principalTable: "BuyOrders",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_SaleOrderDetails_SaleOrders_SaleOrderId",
                table: "SaleOrderDetails",
                column: "SaleOrderId",
                principalTable: "SaleOrders",
                principalColumn: "Id");
        }
    }
}
